﻿// -----------------------------------------------------------------------
// <copyright file="SubscriptionQueryControl.cs" company="Zen Design Corp">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Zen.BlackBerry.Pap.Control
{
	using System;
	using System.Xml;
	using System.Xml.Serialization;
	using Zen.BlackBerry.Common;
	using Zen.BlackBerry.Pap.Parser;

	/// <summary>
	/// Represents a subscription query control message (XML).
	/// </summary>
	public class SubscriptionQueryControl : PapControl, IXmlSerializable
	{
		/// <summary>
		/// Gets or sets the push service id.
		/// </summary>
		/// <value>The push service id.</value>
		public string PushServiceId
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the addresses.
		/// </summary>
		/// <value>The addresses.</value>
		public string[] Addresses
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the status.
		/// </summary>
		/// <value>The status.</value>
		public SubscriptionStatus? Status
		{
			get;
			set;
		}

		#region IXmlSerializable Members

		/// <summary>
		/// This method is reserved and should not be used. When implementing the IXmlSerializable interface, you should return null (Nothing in Visual Basic) from this method, and instead, if specifying a custom schema is required, apply the <see cref="T:System.Xml.Serialization.XmlSchemaProviderAttribute"/> to the class.
		/// </summary>
		/// <returns>
		/// An <see cref="T:System.Xml.Schema.XmlSchema"/> that describes the XML representation of the object that is produced by the <see cref="M:System.Xml.Serialization.IXmlSerializable.WriteXml(System.Xml.XmlWriter)"/> method and consumed by the <see cref="M:System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader)"/> method.
		/// </returns>
		public System.Xml.Schema.XmlSchema GetSchema()
		{
			return null;
		}

		/// <summary>
		/// Generates an object from its XML representation.
		/// </summary>
		/// <param name="reader">The <see cref="T:System.Xml.XmlReader"/> stream from which the object is deserialized.</param>
		public void ReadXml(XmlReader reader)
		{
			throw new NotImplementedException();
		}

		/// <summary>
		/// Converts an object into its XML representation.
		/// </summary>
		/// <param name="writer">The <see cref="T:System.Xml.XmlWriter"/> stream to which the object is serialized.</param>
		public void WriteXml(XmlWriter writer)
		{
			writer.WriteAttributeString("pushservice-id", PushServiceId);

			if (Addresses != null && Addresses.Length > 0)
			{
				foreach (string address in Addresses)
				{
					writer.WriteStartElement("address");
					writer.WriteAttributeString("address-value", address);
					writer.WriteEndElement();
				}
			}

			if (Status.HasValue)
			{
				writer.WriteStartElement("status");
				writer.WriteEnum("status-value", Status.Value);
				writer.WriteEndElement();
			}
		}

		#endregion
	}
}
